< previous page page_431 next page >

Page 431
You can test this behavior at designtime by assigning a picture to an Image control, setting the Stretch property to True, and resizing the control. Figure 19.5 shows the same picture in several Image controls. The one with the Stretch property set to False shows the image at its original size, and others show some possible effects of resizing the Image control if the Stretch property is set to True.
0431-01.jpg
Figure 19.5
The 
Stretch property of the Image
control allows you to resize a picture.
tip.gif
If you are loading pictures of different sizes into an Image control in your application, you should set the Stretch property to True. Otherwise, the size of the Image control changes with each picture. If the appearance of the pictures is unsuitable due to stretching, consider using the PictureBox control. It may be more desirable in some circumstances, such as a displaying a person's photograph, to hide some of the picture rather than show it all distorted.

Using the PictureBox Control
pbcontrol.gif Although the PictureBox control uses more system resources than the Image control, it has some added features. First, it can be used as a container for other controls, allowing you to treat controls drawn within it as a group. In addition, you can use drawing methods (for example, Line and Print) to draw on the picture box.
To use the picture box as a container, first draw a picture box on your form. Next, select a control from the toolbox, and draw the control within the boundaries of the picture box. When you move the picture box or set its Visible property, the controls contained within it are also affected.
The most striking difference between the Image and PictureBox is that the PictureBox does not allow resizing of the picture. The default behavior of the PictureBox control is to show only as much of a picture as can fit in its current boundaries. If the picture is larger than the PictureBox control, the upper-left corner of the picture is shown. If the picture is smaller than the PictureBox control, space is left around the edges of the picture. In either case, the entire picture, displayed or not, is loaded in the PictureBox control and available if the control is resized. Setting the AutoSize property to True changes this default behavior, causing the PictureBox control to resize itself to fit the current picture. As with the Image control, the top-left corner of the control is anchored in place, and resizing of the control occurs to the right and down. However, don't confuse the AutoSize property with the Image control's Stretch property; the PictureBox control always preserves the aspect ratio of the picture being shown, regardless of the dimensions of the PictureBox control. Figure 19.6 shows the same picture in each of two PictureBox controlsone with the AutoSize property set to False and the other with the AutoSize property set to True.

 
< previous page page_431 next page >